createtask = function(name,t)
   local task = {
     complete = false,
     __name = name,
     subtasks = list.new(),
     addsubtask = function(self,subtask)
       self.subtasks:pushleft(subtask)
     end,
     removesubtask = function(self,subtask)
       self.subtasks:popleft()
     end,
     check = function(self,dt)
       if self.complete == true then
         print(self.__name.." Task Finished")
         return "finished","continue"       
       end
       if #self.subtasks == 0 then
         self.complete = true
         print(self.__name.." Task Block Siblings")
         return "inprogress","blocksiblings"
       else
         print(self.__name.." Task Continue")
         return "inprogress","continue"
       end
     end,
     act = function(self,dt)
       local finished, state = "finished", "inprogress"
       -- If all subtasks are finished, and we are finished finished is true
       local st
       for st in list.entries(self.subtasks) do
         finished,state = st:act(dt)
         if finished == "finished" then
           self:removesubtask(st)
         end
         if state == "continue" then
           -- Task is in progress and other tasks may continue
         elseif state == "blocksiblings" then
           -- Task is in progress and blocking other sibling tasks (that follow this one)
           break
         elseif state == "blockall" then
           -- Task needs full attention and is blocking all other tasks
           return finished, state
         end
       end 
       -- Do task logic
       
       -- Check if finish conditions have been met
       finished, state = self:check(dt)
       return finished, state  
     end,
  }
  return task
end

if false then
    taskA = createtask("A")
    taskB = createtask("B")
    taskC = createtask("C")
    taskD = createtask("D")
    
    taskA:addsubtask(taskB)
    taskA:addsubtask(taskC)
    taskA:act() -->C Inprogress
    taskA:act() -->C Finished
    taskA:addsubtask(taskD)
    taskA:act() -->D Inprogress
    taskA:act() -->D Finished
    taskA:act() -->B Inprogress
    taskA:act() -->B & A Finished
    taskA:act() -->A Finished

end
